I always run the latest LTS version of Ubuntu on all my servers. Unfortunately, the Nginx versions tend to be quite the bit behind the current release. So how do you get an updated, current version of without resorting to having to maintain the packages yourself? Luckily, the Nginx team have their own Ubuntu apt repository so it’s easy to keep current with the latest version of Nginx.
In general, you should deploy the NGINX mainline branch at all times. You may wish to use stable if you are concerned about possible impacts of new features, such as incompatibility with third-party modules or the introduction of bugs in new features.
Source: NGINX 1.6 and 1.7 released – Which version should I use?
First, to avoid missing PGP key during installation and upgrades, install the Nginx team’s package signing key:
$ curl -s https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
Add the repo to your apt sources:
$ sudo echo -e "deb https://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx\ndeb-src https://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" > /etc/apt/sources.list.d/nginx.list
Resynchronize the package index files from their sources:
$ sudo apt-get update
If you are installing nginx:
$ sudo apt-get install nginx
… or if you are upgrading:
$ sudo apt-get dist-upgrade
And you’re done :-)
Maybe you are also looking for how to install the latest version of PHP?
… or even replace PHP with HHVM.
Hi, this is a really nice article, but I have a couple of questions if I may.
If I run the apt-get install nginx, will it install it with http2 module in it?
Is there a guide on how to build nginx to support http2?
Off-topic: I’ve tried to add the php fpm to nginx and didn’t worked like in previous versions, any thoughts on that?
Kind regards, Alex.
Nginx version 1.9.5 from the official Nginx APT repository includes the HTTP/2 module.
If you’re building Nginx yourself, add
--with-http_v2_module
to the configure arguments.There’s no change in how it handles upstreams or fastcgi, so it works just as in previous versions.
I have no idea why this is not working :(
Could you give your advice on this?
I’ve uploaded 3 screenshots including the configuration, and the php file/result.
http://alexhera.me/1.png
http://alexhera.me/2.png
http://alexhera.me/3.png
Would really appreciate it if you could give me a hand in fixing it. :)
Best regards,
Alex.
None of the screenshots are working, but I see that you are running Nginx 1.9.5 which currently is the newest Nginx version, so I guess you fixed it.
Hi, short update, I googled around and I think it should work ok.
This is what I did on a new ubuntu 14.04 installation.
Installed nginx 1.9.5 from repository
Install php fast cgi
Here were the problems in my case:
The default value of the nginx user in nginx.conf was “nginx” and not “www-data”. Changed to “www-data”.
In the “/etc/php5/fpm/pool.d/www.conf” I’ve un- commented the line with the “listen.mode = 0660”
After that I’ve added two additional lines in “fastcgi_params” from nginx dir.
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
This is the rest of the editing made in default configuration file for nginx.
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Hope this is useful for someone. :)
Best regards,
Alexandru.
Like your posts man! :)
Thank you so much. works
Why i get the 1.9.12 version ???
Because that’s the newest version in mainline. What version did you expect?
I love you Bjorn! Thanks so much for sharing this. :)
I note that the key is been got via http and not https so wouldn’t that be vulnerable to MITM attack?
Additionally the piped command fails as its not been run by root!
the command in question:
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add –
maybe this would be more secure?
$ curl https://nginx.org/keys/nginx_signing.key | sudo apt-key add –
works for me!
You are absolutely right. I’ve fixed this, and a few similar things in the post now.
Thank you!
i wanted to know which latest version of nginx install on ubuntu 10.04
Hi, it is nice article.
I am facing one issue in website.
Issue is, sometime HTML code is displaying without rendering.
Currently using nginx 1.12 and http 1.1. so planning upgrade to nginx latest version and http2.
Please suggest which version of nginx needs to be install and how to enable http2.
HTTP/2 became available in Nginx version 1.9.5, but I highly recommend that you install the latest version available. Newer versions also have support for HTTP/2 push. Instructions on how to enable HTTP/2 in Nginx is found here.